let url = {
	index: '/api/index',
	login: '/api/auth/login',
	register: '/api/auth/register',
	getUserInfo: '/api/user',
	updateUserInfo: '/api/user',
	updateUserAvatar: '/api/user/avatar',
	getOssToken: '/api/auth/oss/token',
	logout: '/api/auth/logout',
	getGoodsCate: '/api/goods',
	getGoodsDetail: '/api/goods/',
	collect: '/api/collects/goods/',
	getCollects: '/api/collects',
	carts: '/api/carts',
	setCartsChecked: '/api/carts/checked',
	previewOrder: '/api/orders/preview',
	orders: '/api/orders',
	address: '/api/address',
}

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	// 首页
	let getIndex = (params = {}) => vm.$u.get(url.index, params)

	// 商品
	let getGoodsCate = (params = {}) => vm.$u.get(url.getGoodsCate, params)
	let getGoodsDetail = params => vm.$u.get(url.getGoodsDetail + params)
	let collect = params => vm.$u.post(url.collect + params)

	// 收藏
	let getCollects = (params = {}) => vm.$u.get(url.getCollects, params)

	// 购物车
	let carts = (params = {}) => vm.$u.get(url.carts, params)
	let addCarts = params => vm.$u.post(url.carts, params)
	let removeCarts = params => vm.$u.delete(url.carts+'/' + params)
	let setCartsNum = ({ id, num }) => vm.$u.put(url.carts+'/' + id, { num })
	let setCartsChecked = params => vm.$u.patch(url.setCartsChecked, params)
	
	// 订单
	let previewOrder = () => vm.$u.get(url.previewOrder)
	let getOrders = params => vm.$u.get(url.orders, params)
	let addOrder = params => vm.$u.post(url.orders, params)
	
	// 地址
	let getAddress = () => vm.$u.get(url.address)
	let addAddress = params => vm.$u.post(url.address, params)
	let updateAddress = params => vm.$u.put(url.address+'/'+params.id, params)
	let removeAddress = params => vm.$u.delete(url.address+'/'+params)
	
	// 个人中心
	let login = params => vm.$u.post(url.login, params)
	let register = params => vm.$u.post(url.register, params)
	let getUserInfo = () => vm.$u.get(url.getUserInfo)
	let updateUserInfo = params => vm.$u.put(url.updateUserInfo, params)
	let updateUserAvatar = params => vm.$u.patch(url.updateUserAvatar, params)
	let getOssToken = () => vm.$u.get(url.getOssToken)
	let logout = () => vm.$u.post(url.logout)
	


	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		getIndex,
		login,
		register,
		getUserInfo,
		updateUserInfo,
		updateUserAvatar,
		getOssToken,
		logout,
		getGoodsCate,
		getGoodsDetail,
		collect,
		getCollects,
		carts,
		addCarts,
		removeCarts,
		setCartsNum,
		setCartsChecked,
		previewOrder,
		getOrders,
		addOrder,
		getAddress,
		addAddress,
		updateAddress,
		removeAddress
	}
}

export default {
	install
}
